package Terminal.UI.InterfacceConsulente;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import Terminal.Entity.Dominio.ETask;
import Terminal.UI.PanelComponent;
import Terminal.UI.PannelloDatiDecoretor;

public class PannelloDatiTask extends PannelloDatiDecoretor{
	
	private ETask task;
	private JLabel tasktitololabel;
	private JLabel tasktitolotextlabel;
	private JLabel taskidlabel;
	private JLabel taskidtextlabel;
	private JLabel taskiniziolabel;
	private JLabel taskiniziotextlabel;
	private JLabel taskscadenzalabel;
	private JLabel taskscadenzatextlabel;
	private JLabel taskstatolabel;
	private JLabel taskstatotextlabel;
	private JLabel taskconsulentelabel;
	private JLabel taskconsulentetext;
	private JLabel taskcostoorariolabel;
	private JLabel taskcostoorariotextlabel;
	private JLabel taskcostototalelabel;
	private JLabel taskcostototaletextlabel;


	public PannelloDatiTask(PanelComponent parent, ETask task){
		super(parent);
		this.task=task;
	}
	@Override
	public JPanel createComponents() {
		
		pannellocomponente = new JPanel(null);
		pannellocomponente.setBackground(Color.white);
		
        /*title= BorderFactory.createTitledBorder("Descrizione progetto");
        pannellocomponente.setBorder(title);*/
		////////////////////////////////////PANNELLO DI DESCRIZIONE////////////////////////////////////
		       
      

        
		tasktitololabel = new JLabel("Titolo:");
		tasktitololabel.setLocation(40,0);
		tasktitololabel.setPreferredSize(new Dimension(200,40));
		tasktitololabel.setSize(tasktitololabel.getPreferredSize());
		tasktitololabel.setFont(new Font(tasktitololabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(tasktitololabel);
		
		
		
        
        tasktitolotextlabel = new JLabel();
        tasktitolotextlabel.setLocation(200, tasktitololabel.getLocation().y);
		tasktitolotextlabel.setPreferredSize(new Dimension(200, 40));
		tasktitolotextlabel.setSize(tasktitolotextlabel.getPreferredSize());
		pannellocomponente.add(tasktitolotextlabel);
		
		tasktitolotextlabel.setFont(new Font(tasktitolotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		
		taskidlabel = new JLabel("Identificatore:");
		//taskidlabel.setLocation(50, tasktitololabel.getLocation().y+tasktitololabel.getPreferredSize().height);
		taskidlabel.setLocation(40,30);
		taskidlabel.setPreferredSize(new Dimension(200,40));
		taskidlabel.setSize(taskidlabel.getPreferredSize());
		taskidlabel.setFont(new Font(taskidlabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(taskidlabel);
       
        
        
       
		taskidtextlabel= new JLabel();
		taskidtextlabel.setLocation(200,taskidlabel.getLocation().y);
		taskidtextlabel.setPreferredSize(new Dimension(200, 40));
		taskidtextlabel.setSize(taskidtextlabel.getPreferredSize());
		pannellocomponente.add(taskidtextlabel);
		
		taskidtextlabel.setFont(new Font(taskidtextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));

		
		taskiniziolabel = new JLabel("Data di inizio:");
		//taskiniziolabel.setLocation(50, taskidlabel.getLocation().y+taskidlabel.getPreferredSize().height);
		taskiniziolabel.setLocation(40,60);
		taskiniziolabel.setPreferredSize(new Dimension(200, 40));
		taskiniziolabel.setSize(taskiniziolabel.getPreferredSize());
		taskiniziolabel.setFont(new Font(taskiniziolabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(taskiniziolabel);
        
		taskiniziotextlabel = new JLabel();
		taskiniziotextlabel.setLocation(200,taskiniziolabel.getLocation().y);
		//taskiniziotextlabel.setLocation(220,110);
		taskiniziotextlabel.setPreferredSize(new Dimension(200, 40));
		taskiniziotextlabel.setSize(taskiniziotextlabel.getPreferredSize());
		pannellocomponente.add(taskiniziotextlabel);
		taskiniziotextlabel.setFont(new Font(taskiniziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
	
		taskscadenzalabel = new JLabel("Data di Fine:");
		taskscadenzalabel.setLocation(400,taskiniziolabel.getLocation().y);
		taskscadenzalabel.setPreferredSize(new Dimension(200,40));
		taskscadenzalabel.setSize(taskscadenzalabel.getPreferredSize());
		taskscadenzalabel.setFont(new Font(taskscadenzalabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(taskscadenzalabel);
		
        
        taskscadenzatextlabel = new JLabel();
        taskscadenzatextlabel.setLocation(550,taskscadenzalabel.getLocation().y);
        taskscadenzatextlabel.setPreferredSize(new Dimension(150, 40));
		taskscadenzatextlabel.setSize(taskscadenzatextlabel.getPreferredSize());
		pannellocomponente.add(taskscadenzatextlabel);
		
		taskscadenzatextlabel.setFont(new Font(taskscadenzatextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		taskstatolabel = new JLabel("Stato:");
		taskstatolabel.setLocation(40,90);
		taskstatolabel.setPreferredSize(new Dimension(200,40));
		taskstatolabel.setSize(taskstatolabel.getPreferredSize());	
		taskstatolabel.setFont(new Font(taskstatolabel.getFont().getFontName(), Font.BOLD,size_font_title));
		pannellocomponente.add(taskstatolabel);
		
        
        taskstatotextlabel = new JLabel();
        taskstatotextlabel.setLocation(200,taskstatolabel.getLocation().y);
        taskstatotextlabel.setPreferredSize(new Dimension(200, 40));
		taskstatotextlabel.setSize(taskstatotextlabel.getPreferredSize());
		//taskstatotextlabel.setFont(new Font(taskstatotextlabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(taskstatotextlabel);
				
		taskstatotextlabel.setFont(new Font(taskstatotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		taskconsulentelabel = new JLabel("Consulente:");
		//taskconsulentelabel.setLocation(40,160);
		taskconsulentelabel.setLocation(40,120);
		taskconsulentelabel.setPreferredSize(new Dimension(200,40));
		taskconsulentelabel.setSize(taskconsulentelabel.getPreferredSize());
		taskconsulentelabel.setFont(new Font(taskconsulentelabel.getFont().getName(), Font.BOLD, size_font_title));
		pannellocomponente.add(taskconsulentelabel);
        
        taskconsulentetext = new JLabel();
       
        taskconsulentetext.setLocation(200,taskconsulentelabel.getLocation().y);
        //taskconsulentetext.setLocation(220,210);
        taskconsulentetext.setPreferredSize(new Dimension(200, 40));
        taskconsulentetext.setSize(taskconsulentetext.getPreferredSize());
        taskconsulentetext.setFont(new Font(taskconsulentetext.getFont().getName(), Font.ITALIC, size_font_values));
		pannellocomponente.add(taskconsulentetext);
		
		

		
		
		visualizzaElemento(task);
		
//+taskscadenzalabel.getSize().width
		super.setSize(taskscadenzatextlabel.getLocation().x+100,taskconsulentetext.getLocation().y+taskconsulentetext.getSize().height);
		
		//setSize(700,200);
		
		return pannellocomponente;
	}
	
	
	public void visualizzaElemento(Object obj) {
		this.task = (ETask) obj;
		Format dataformat= new SimpleDateFormat("dd/MM/yyyy");
		try{tasktitolotextlabel.setText(task.getTitolo());} catch (Exception e) {tasktitolotextlabel.setText(" ");		}
		try{taskidtextlabel.setText(task.getId()+"");} catch (Exception e) {taskidtextlabel.setText("  ");		}
		try{if(task.getDataInizio()!=null) 	
		{
		Date datetemp= task.getDataInizio();
		taskiniziotextlabel.setText(dataformat.format(datetemp));
		}
		else taskiniziotextlabel.setText("  "); }catch (Exception e) {	taskiniziotextlabel.setText("  ");		}
		try{if(task.getDataFine()!=null)
		{
		Date datetemp= task.getDataFine();
		taskscadenzatextlabel.setText(dataformat.format(datetemp));
		}
		else taskscadenzatextlabel.setText(" ");}catch (Exception e) {	taskscadenzatextlabel.setText(" ");	}
		try{if(task.getConsulenteAttuale()!=null)	taskconsulentetext.setText(task.getConsulenteAttuale().getCognome()+" "+task.getConsulenteAttuale().getNome()+" matricola: "+task.getConsulenteAttuale().getMatricola());else taskconsulentetext.setText("  ");} catch (Exception e) { taskconsulentetext.setText("  ");}
		try{if(task.getStatoObj()!=null) {taskstatotextlabel.setText(task.getStatoObj().getStatoString());
		}
		
		else  taskstatotextlabel.setText(" ");}catch (Exception e) {taskstatotextlabel.setText(" ");	}
		
		
		
		
		}
	
	public void updateSize(){}
	

}


